package test_pkg

import (
	"fmt"
	"time"
)

// 使用 select 切换协程
func pump1(ch chan int) {
	for i := 0; ; i++ {
		ch <- i * 2
	}

}

func pump2(ch chan int) {
	for i := 0; ; i++ {
		ch <- i + 5
	}
}

func suck(ch, ch1 chan int) {
	for {
		select {
		case v := <-ch:
			fmt.Printf("Received on channel 1: %v\n", v)
		case v := <-ch1:
			fmt.Printf("Received on channel 2: %v\n", v)

		}
	}
}

func Test_select() {
	ch := make(chan int)
	ch1 := make(chan int)

	go pump1(ch)
	go pump2(ch1)
	go suck(ch, ch1)
	time.Sleep(1 * time.Microsecond)
}
